Imports System.Data
Imports System.Data.SqlClient
Imports System.Security.Cryptography

Partial Class Client_frmRegisteration
    Inherits System.Web.UI.Page
    'Dim dr As SqlDataReader
    Dim conn As New SqlString()
    Dim _BO As New Bo()
    Dim _UserVO As New UserVO()
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        Dim md5Hasher As MD5 = MD5.Create()
        Dim data As Byte() = md5Hasher.ComputeHash(Encoding.[Default].GetBytes(txtPassword.Text))
        Dim sBuilder As New StringBuilder()
        For i As Integer = 0 To data.Length - 1
            sBuilder.Append(data(i).ToString("x2"))
        Next
        'MsgBox(sBuilder.ToString())

        Try
            Session("UserId") = txtUserId.Text
            _UserVO.UserId = txtUserId.Text
            _UserVO.Password = sBuilder.ToString()
            _UserVO.FirstName = txtFirstName.Text
            _UserVO.LastName = txtLastName.Text
            _UserVO.Address = txtAddress.Text
            _UserVO.Country = ddlCountry.SelectedValue.ToString
            _UserVO.State = ddlState.SelectedValue.ToString
            _UserVO.City = ddlCity.SelectedValue.ToString
            _UserVO.Gender = rdbGender.SelectedValue
            _UserVO.BirthDate = txtBirthDate.Text
            _UserVO.MobileNumber = txtMobileNumber.Text
            _UserVO.PhoneNumber = txtPhoneNumber.Text
            _UserVO.EmailId = txtEmailId.Text
            _UserVO.AnniversaryDate = txtAnniversaryDate.Text
            _UserVO.Zipcode = txtZipcode.Text
            _BO.InsertUser(_UserVO)
            ClearAll()
            Response.Redirect("frmDataList.aspx", False)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub ClearAll()
        txtUserId.Text = ""
        txtPassword.Text = ""
        txtAddress.Text = ""
        txtAnniversaryDate.Text = ""
        txtZipcode.Text = ""
        txtEmailId.Text = ""
        txtBirthDate.Text = ""
        txtPhoneNumber.Text = ""
        txtMobileNumber.Text = ""
        txtFirstName.Text = ""
        txtLastName.Text = ""
        MsgBox("Successful Registeration")
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            CountryData()
            StateData()
            CityData()
        End If
    End Sub
    Public Sub CountryData()
        Dim dtCountry As DataTable
        dtCountry = _BO.getcountry()
        ddlCountry.DataSource = dtCountry
        ddlCountry.DataValueField = dtCountry.Columns(0).ToString
        ddlCountry.DataTextField = dtCountry.Columns(1).ToString
        ddlCountry.DataBind()
    End Sub
    Sub StateData()
        Dim dtState As DataTable
        dtState = _BO.getstate(ddlCountry.SelectedValue)
        ddlState.DataSource = dtState
        ddlState.DataValueField = dtState.Columns(1).ToString
        ddlState.DataTextField = dtState.Columns(2).ToString
        ddlState.DataBind()
    End Sub
    Sub CityData()
        Dim dtCity As DataTable
        dtCity = _BO.getCity(ddlState.SelectedValue)
        ddlCity.DataSource = dtCity
        ddlCity.DataValueField = dtCity.Columns(2).ToString
        ddlCity.DataTextField = dtCity.Columns(3).ToString
        ddlCity.DataBind()
    End Sub
    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        StateData()
        CityData()
    End Sub
    Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
        CityData()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtUserId.Text = ""
        txtPassword.Text = ""
        txtAddress.Text = ""
        txtAnniversaryDate.Text = ""
        txtZipcode.Text = ""
        txtEmailId.Text = ""
        txtBirthDate.Text = ""
        txtPhoneNumber.Text = ""
        txtMobileNumber.Text = ""
        txtFirstName.Text = ""
        txtLastName.Text = ""
    End Sub
End Class
